package tech.topcoder.springcloud.simpleservice.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.topcoder.springcloud.simpleservice.bean.Demo;
import tech.topcoder.springcloud.simpleservice.mybatis.Pagination;
import tech.topcoder.springcloud.simpleservice.service.DemoService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by china on 2016/12/10.
 */

@Controller
@RequestMapping("/demo")
public class DemoController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(DemoController.class);

    @Resource
    private DemoService demoService;

    @RequestMapping("/list")
    @ResponseBody
    public Object list(@RequestParam(defaultValue = "0") int start,
                       @RequestParam(defaultValue = "10") int length,
                       @RequestParam(defaultValue = "") String keyword) {
        Pagination<Demo> pageData = demoService.getPageList(start, length, keyword);

        Map<String, Object> result = new HashMap<>();
        result.put("total", pageData.getTotal());
        result.put("list", pageData.getData());

        return result;
    }

}
